package com.situation.controller;

import com.github.pagehelper.PageInfo;
import com.situation.annotation.ControllerEndpoint;
import com.situation.pojo.DO.TbLog;
import com.situation.service.TbLogService;
import com.situation.util.RespUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/log")
public class TbLogController {
    @Autowired
    private TbLogService tbLogService;

    /**
     * 添加系统日志
     * @param tbLog 系统日志对象
     * @return int类型，1为成功，0为失败
     */
    @PostMapping("/add")
    public RespUtil add(TbLog tbLog){
        int i = tbLogService.addTbLog(tbLog);
        if (i==1){
            return RespUtil.ok();
        }else
            return RespUtil.fail();
    }

    /**
     * 删除单个日志
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @RequiresPermissions({"log:delete"})
    public RespUtil delete(@PathVariable("id")Long id){
        int i = tbLogService.delete(id);
        if (i==1){
            return RespUtil.ok();
        }else
            return RespUtil.fail();
    }

    /**
     * 批量删除日志
     * @param ids
     * @return
     */
    @DeleteMapping("/batchDelete/{ids}")
    @RequiresPermissions({"log:batchDelete"})
    public RespUtil batchDelete(@PathVariable("ids")Long[] ids){
        int i = tbLogService.batchDelete(ids);
        if (i==1){
            return RespUtil.ok();
        }else
            return RespUtil.fail();
    }

    /**
     * 多条件查询系统日志
     * @param tbLog
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/findLogList")
    public RespUtil findLogList(TbLog tbLog,int pageNum,int pageSize){
        PageInfo<TbLog> tbLogPageInfo = tbLogService.selectByMore(tbLog,pageNum,pageSize);
        if (tbLogPageInfo!=null){
            return RespUtil.ok().setData(tbLogPageInfo);
        }else
            return RespUtil.fail();
    }
}
